package com.mindtalk.helper;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.mindtalk.R;
import com.mindtalk.transferdata.MyChannelsData;

/*
 * Adapter Khusus Untuk Tab Conferences
 * */

public class ConferenceAdapter extends ArrayAdapter<MyChannelsData>{
		
	/* Daftar Variable */
	/*
	 * Inflater
	 * */
	LayoutInflater mInflater;
	/*
	 * Konstruktor
	 * */
	public ConferenceAdapter( Context context,ArrayList<MyChannelsData> data,int textViewResourceId, LayoutInflater inflater){
		super(context, textViewResourceId);
		this.mInflater = inflater;
	}
	
	/*
	 * Get View
	 * */
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ImageView imageView;
		TextView tv_roomname;
		TextView tv_onlineUser;
		TextView tv_unreadChat;
		
		if(convertView == null){
			convertView = mInflater.inflate(R.layout.conferences,null);
			imageView = (ImageView)convertView.findViewById(R.id.img_conferences);
			tv_roomname = (TextView)convertView.findViewById(R.id.tv_conferences_roomname);
			tv_onlineUser = (TextView)convertView.findViewById(R.id.tv_conferences_onlineuser);
			tv_unreadChat = (TextView)convertView.findViewById(R.id.tv_conferences_unreadchat);			
		}else{		
			imageView = (ImageView)convertView.getTag(R.id.img_conferences);
			tv_roomname = (TextView)convertView.getTag(R.id.tv_conferences_roomname);
			tv_onlineUser = (TextView)convertView.getTag(R.id.tv_conferences_onlineuser);
			tv_unreadChat = (TextView)convertView.getTag(R.id.tv_conferences_unreadchat);			
		}
		if(imageView!=null&&tv_onlineUser!=null&&tv_roomname!=null&&tv_unreadChat!=null){
			imageView.setImageResource(R.drawable.icon);
			tv_roomname.setText(this.getItem(position).roomName);
			tv_onlineUser.setText(this.getItem(position).onlineUser + " Online User");
			tv_unreadChat.setText(this.getItem(position).unreadChat+"asd");
		}
		
		return convertView;
	}
}
